package com.jtny.nytb.equipment.utils;

import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class CopyList {

    public static <K, V> List<V> copyList(List<K> source, Class<V> zclass) {
        if (CollUtil.isEmpty(source)) {
            return new ArrayList<>(0);
        }
        List<V> target = new ArrayList<>(0);
        source.forEach(e -> {
            try {
                V v = zclass.getConstructor().newInstance();
                BeanUtils.copyProperties(e, v);
                target.add(v);
            } catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
                     InvocationTargetException noSuchMethodException) {
                noSuchMethodException.printStackTrace();
            }
        });
        return target;
    }

}


